﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using Microsoft.VisualStudio.Shell;

namespace CodeCounsel.SharePoint.RibbonDesigner
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
    [System.Runtime.InteropServices.ComVisibleAttribute(false)]
    public sealed class DefaultToolboxTabAttribute : RegistrationAttribute
    {
        public Guid EditorFactory { get; set; }
        public string TabName { get; set; }

        public DefaultToolboxTabAttribute(string editorFactory, string tabName)
        {
            EditorFactory = new Guid(editorFactory);
            TabName = tabName;
        }

        public override void Register(RegistrationAttribute.RegistrationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            using (Key key = context.CreateKey(
                String.Format(CultureInfo.InvariantCulture, "Editors\\{0}",
                    EditorFactory.ToString("B"))))
            {
                key.SetValue("DefaultToolboxTab", TabName);
            }
        }

        public override void Unregister(RegistrationAttribute.RegistrationContext context)
        {
        }
    }
}
